package com.wd.tech.Base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.wd.tech.contracts.Contract;

/**
 * date:2020/7/2
 * author:王成虎(13671)
 * month:七月
 * function:
 */
public abstract class BaseFragment<P extends BasePresenter> extends Fragment implements Contract.IView {

    public P mPresenter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(initLaout(), null);
        initViews(inflate);
        return inflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mPresenter=initPresenter();
        if (mPresenter!=null){
            mPresenter.onBulde(this);
        }
        initData();
    }

    protected abstract void initData();

    protected abstract P initPresenter();

    protected abstract void initViews(View inflate);

    protected abstract int initLaout();

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.onDetry();
    }

}
